﻿using System.Collections.Generic;
using System.Linq;
using GONES.Model;

namespace GONES.IDAL
{
    public interface IRepository<T> where T : EntityBase
    {
        /// <summary>
        /// 通过主键返回对象
        /// </summary>
        /// <param name="id">主键值</param>
        /// <returns></returns>
        T Get(object id);

        /// <summary>
        /// 保存对象
        /// </summary>
        /// <param name="model">实体</param>
        /// <returns></returns>
        object Save(T model);

        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="model">实体</param>
        void Update(T model);

        /// <summary>
        /// 保存或更新对象
        /// </summary>
        /// <param name="model">实体</param>
        void SaveOrUpdate(T model);

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="model">实体</param>
        void Delete(T model);

        /// <summary>
        /// 跟据Hql返回长整形
        /// </summary>
        /// <param name="hql"></param>
        /// <returns></returns>
        long ExecHqlResultLong(string hql);

        /// <summary>
        /// 跟据Hql返回对象数据
        /// </summary>
        /// <param name="hql"></param>
        /// <returns></returns>
        object ExecHqlUniqueResult(string hql);

        /// <summary>
        /// 跟据Sql返回对象数组
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        object ExecSqlUniqueResult(string sql);

        /// <summary>
        /// 跟据Hql返回对象数据
        /// </summary>
        /// <param name="hql"></param>
        /// <returns></returns>
        object[] ExecHql(string hql);

        /// <summary>
        /// 跟据Sql返回对象数组
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        object[] ExecSql(string sql);


        /// <summary>
        /// 获取记录列表
        /// </summary>
        /// <returns></returns>
        IQueryable<T> GetList();

        /// <summary>
        /// 跟据hql返回实体列表
        /// </summary>
        /// <param name="hql"></param>
        /// <returns></returns>
        IList<T> GetHqlList(string hql);

        /// <summary>
        /// 跟据hql返回实体列表
        /// </summary>
        /// <param name="hql"></param>
        /// <param name="start"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        IList<T> GetHqlList(string hql, int start, int limit);

        /// <summary>
        /// 跟据hql返回对象数组列表
        /// </summary>
        /// <param name="hql"></param>
        /// <returns></returns>
        IList<object []> GetHqlObject(string hql);


        /// <summary>
        /// 跟据sql返回实体列表
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        IList<T> GetSqlList(string sql);

        /// <summary>
        /// 跟据sql返回对象数组列表
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        IList<object[]> GetSqlObject(string sql);

        /// <summary>
        /// 跟据sql返回对象数组列表,带分页
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="start"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        IList<object[]> GetSqlObject(string sql, int start, int limit);



        /// <summary>
        /// 批量插入使用StatelessSession
        /// </summary>
        /// <param name="list">传入的集合名</param>
        void Add(IList<T> list); 


        /// <summary>
        /// 执行sql语句
        /// </summary>
        /// <param name="list">sql 语句集合</param>
         void ExecSql(IList<string> list);



        /// <summary>
        /// 使用batchSize插入集合
        /// </summary>
        /// <param name="list"></param>
         void AddWithBatchSize(IList<T> list);


         object ESql(string sql);
    }
}